import {
  UPDATE_LOADING,
  UPDATE_DIRECTION,
  DDCONFIG_SUCCESS,
  DDCONFIG_ERROR,
  UPDATE_CODE,
  LOGIN_SUCCESS,
  LOGIN_ERROR,
  // UPDATE_SYS_LEVEL,
  INCREMENT,
  DECREMENT,
  HIDE_COVER,
  SHOW_COVER,
  UPDATE_TOKEN,
  UPDATE_USER,
  UPDATE_TARGET,
  UPDATE_CLIENT_DETAIL,
  HIDE_DIALOG,
  SHOW_DIALOG,
  UPDATE_DIALOG_MESSAGE,
  UPDATE_DDUSER,
  UPDATE_CUSTOM_SOURCES,
  UPDATE_SITE_ID,
  UPDATE_FILTER_OPTIONS,
  UPDATE_TOPFILTER_LOADING,
  UPDATE_SOURCE_FILTER,
  UPDATE_CHANNEL_FILTER,
  UPDATE_LOCATION,
  UPDATE_CHANNEL,
  UPDATE_WINDOW_SIZE
} from '../mutation-types'

import actions from '../actions'

const state = {
  count: 0,
  isLoading: false, // 路由加载标志位
  direction: 'forward', // 路由动画变量
  ddConfig: null,
  ddConfigStatus: null,
  code: 333,
  site_id: 1,
  topFilterLoading: false,
  location: {},
  ddUser: {},
  windowSize: {},
  user: {
    // "id": 1,
    // "uid": 2,
    // "username": "Evan",
    // "mobile": "18620300370",
    // "reg_time": "2017-03-22 11:34:28",
    // "insert_time": "2017-03-22 11:34:28",
    // "headimgurl": "http://static.dingtalk.com/media/lADOAIBV2TAw_48_48.jpg",
    // "ding_uid": "007",
    // "teams": [
    //   {
    //   "team_id": 3
    //   }
    // ],
    // "is_team_manager": 1
  },
  imgServer: '//fin.91mycloud.com/',
  isShowCover: false,
  token: '',
  target: null,
  updateSourceFilter: 0,
  updateChannelFilter: 0,
  dialogShow: false,
  dialogMessage: '',
  clientsDetail: {},
  customSources: {},
  channel: {},
  filterOptions: [
    {
      title: '搜索',
      class: 'txt-center',
      showArrow: true,
      name: 'search'
    },
    {
      title: '筛选',
      class: 'txt-center',
      value: '6',
      checked: '',
      name: 'filter',

      options: [
        // 未联系时间开始
        {
          text: '未联系时间',
          value: '1',
          checked: '-1',
          name: 'connet_time',
          options: [
            {
              text: '不限',
              value: '-1'
            },
            {
              text: '一周到两周',
              value: '1'
            },
            {
              text: '两周到一月',
              value: '2'
            },
            {
              text: '一月到两月',
              value: '3'
            },
            {
              text: '两月以上',
              value: '4'
            }
          ]
        },
        // 未联系时间结束

        // 负责人开始
        {
          text: '负责人',
          value: '2',
          isMore: true,
          showSearch: true,
          name: 'suid',
          options: [
            // {
            //   text : '营销顾问1',
            //   value : '1'
            // },
            // {
            //   text : '营销顾问2',
            //   value : '2'
            // },
            // {
            //   text : '营销顾问3',
            //   value : '3'
            // }
            {
              text: '不限',
              value: '-1'
            }
          ]
        },
        // 负责人结束

        // 所属团队开始
        {
          text: '所属团队',
          value: '',
          // checked: '1',
          isMore: true,
          showSearch: true,
          name: 'team_id',
          options: [
            // {
            //   text: '不限',
            //   value: '-1'
            // }
            //     {
            //       text : '',
            //       value : '1'
            //     },
            //     {
            //       text : '团队1',
            //       value : '2'
            //     },
            //     {
            //       text : '团队2',
            //       value : '3'
            //     }
          ]
        },
        // 所属团队开始
        {
          text: '是否学员',
          value: '6',
          checked: '-1',
          name: 'is_member',
          options: [
            {
              text: '不限',
              value: '-1'
            },
            {
              text: '是',
              value: '1'
            },
            {
              text: '不是',
              value: '0'
            }
          ]
        },
        // 客户属性开始
        {
          text: '客户属性',
          value: '4',
          checked: '',
          name: 'custom_property',
          options: [
            {
              text: '不限',
              value: '-1'
            },
            {
              text: '一般客户',
              value: '0'
            },
            {
              text: '意向客户',
              value: '1'
            },
            {
              text: '成交客户',
              value: '2'
            },

            {
              text: '无效客户',
              value: '3'
            },

            {
              text: '其他客户',
              value: '4'
            }
          ]
        },
        // 客户属性结束

        // 跟进状态开始
        {
          text: '跟进状态',
          value: '5',
          checked: '',
          name: 'custom_status',
          options: [
            {
              text: '不限',
              value: '-1'
            },
            {
              text: '新客户',
              value: 'NC%23'
            },
            {
              text: '关怀',
              value: 'GH%23'
            },
            {
              text: '预约',
              value: 'YY%23'
            },

            {
              text: '已观校',
              value: 'GM%23'
            },
            {
              text: '已试听',
              value: 'ST%23'
            },

            {
              text: '首次签约',
              value: 'FS%23'
            },

            {
              text: '续报签约',
              value: 'XB%23'
            }
          ]
        },
        {
          text: '宝宝年龄',
          value: '7',
          checked: '',
          name: 'baby_age',
          options: [
            {
              text: '不限',
              value: '-1'
            },
            {
              text: '0-1岁',
              value: '0-12month'
            },
            {
              text: '1-1岁半',
              value: '12month-18month'
            },
            {
              text: '1岁半-2岁',
              value: '18month-24month'
            },
            {
              text: '2-2岁半',
              value: '24month-30month'
            },
            {
              text: '2岁半-3岁',
              value: '30month-36month'
            },
            {
              text: '3岁以上',
              value: '36month-0'
            }
          ]
        },
        {
          text: '是否激活',
          value: '6',
          checked: '',
          name: 'is_activation',
          options: [
            {
              text: '不限',
              value: '-1'
            },
            {
              text: '是',
              value: '1'
            },
            {
              text: '不是',
              value: '0'
            }
          ]
        },
        {
          text: '分配时间',
          value: '10',
          checked: '',
          name: 'insert_time',
          options: []
        }
      ]
    },

    {
      title: '排序',
      class: 'txt-center',
      checked: '',
      name: 'order_by',
      options: [
        {
          text: '录入时间倒序',
          value: '0'
        },

        {
          text: '跟进时间倒序',
          value: '1'
        },

        {
          text: '更新时间倒序',
          value: '2'
        },

        {
          text: '姓名正序',
          value: '3'
        },
        {
          text: '跟进时间升序',
          value: '4'
        },
        {
          text: '智能排序',
          value: '5'
        },
        {
          text: '分配时间升序',
          value: '6'
        },
        {
          text: '分配时间倒序',
          value: '7'
        },
      ]
    }
  ],
  customStatusOptions: [
    {
      key: 'NC%23',
      value: '新客户'
    },
    {
      key: 'GH%23',
      value: '关怀'
    },
    {
      key: 'YY%23',
      value: '预约'
    },
    {
      key: 'GM%23',
      value: '已观校'
    },
    {
      key: 'ST%23',
      value: '已试听'
    },
    {
      key: 'FS%23',
      value: '首次签约'
    },
    {
      key: 'XB%23',
      value: '续报签约'
    }
  ],
  customPropertyOptions: [
    {
      key: 'YB%23',
      value: '一般客户'
    },
    {
      key: 'YX%23',
      value: '意向客户'
    },
    // {
    //   key: 'YCJ',
    //   value: '成交客户'
    // },

    {
      key: 'WX%23',
      value: '无意向客户'
    },
    {
      key: 'NA%23',
      value: '无效客户'
    },
    {
      key: 'QT%23',
      value: '其它客户'
    }
  ]
}

const mutations = {
  [INCREMENT] (state) {
    state.count++
  },
  [DECREMENT] (state) {
    state.count--
  },
  [UPDATE_LOADING] (state, status) {
    state.isLoading = status
  },
  [UPDATE_DIRECTION] (state, direction) {
    state.direction = direction
  },
  [DDCONFIG_SUCCESS] (state, config) {
    state.ddConfig = config
    state.ddConfigStatus = true
    // console.debug(JSON.stringify(config), 'warnnnnnn')
  },
  [DDCONFIG_ERROR] (state, config) {
    state.ddConfig = null
    state.ddConfigStatus = false
  },

  [UPDATE_CODE] (state, code) {
    state.code = code
  },

  [UPDATE_TOKEN] (state, token) {
    state.token = token
  },

  [LOGIN_SUCCESS] (state, user) {
    state.user = user
  },

  [UPDATE_USER] (state, user) {
    state.user = user
  },

  [LOGIN_ERROR] (state, user) {
    state.user = false
  },

  [HIDE_COVER] (state) {
    state.isShowCover = false
  },

  [SHOW_COVER] (state) {
    state.isShowCover = true
  },

  [UPDATE_TARGET] (state, target) {
    state.target = target
  },

  [UPDATE_CLIENT_DETAIL] (state, clientsDetail) {
    state.clientsDetail = clientsDetail
  },

  [UPDATE_DIALOG_MESSAGE] (state, message) {
    state.dialogMessage = message
  },

  [SHOW_DIALOG] (state) {
    console.log(state)
    state.dialogShow = true
  },

  [HIDE_DIALOG] (state) {
    console.log(state)
    state.dialogShow = false
  },

  [UPDATE_DDUSER] (state, ddUser) {
    state.ddUser = ddUser
  },

  [UPDATE_SITE_ID] (state, siteId) {
    state.site_id = siteId
  },

  [UPDATE_CUSTOM_SOURCES] (state, customSources) {
    state.customSources = customSources
  },
  [UPDATE_CHANNEL] (state, channel) {
    state.channel = channel
  },

  [UPDATE_FILTER_OPTIONS] (state, filterOptions) {
    state.filterOptions = filterOptions
  },

  [UPDATE_TOPFILTER_LOADING] (state, isLoading) {
    state.topFilterLoading = isLoading
  },

  [UPDATE_SOURCE_FILTER] (state, status) {
    state.updateSourceFilter = status
  },

  [UPDATE_CHANNEL_FILTER] (state, status) {
    state.updateChannelFilter = status
  },
  [UPDATE_LOCATION] (state, location) {
    state.location = Object.assign({}, location)
  },
  [UPDATE_WINDOW_SIZE] (state, size) {
    state.windowSize = size;
  },
  INCREMENT (state) {
    console.log('test INCREMENT')
    state.count++
  },

  DECREMENT (state) {
    state.count--
  }
}

export default {
  state,
  mutations,
  actions
}
